#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    int maxSumTwoNoOverlap(vector<int>& nums, int firstlen, int secondlen) {
        int ret=0;
        int n=nums.size();
        vector<int> sum(n+1,0);
        for(int i=1;i<=n;i++) sum[i]=sum[i-1]+nums[i-1];
        int maxa=0;
        int maxb=0;
        for(int i=firstlen+secondlen;i<=n;i++)
        {
            maxa=max(maxa,sum[i-secondlen]-sum[i-firstlen-secondlen]);
            maxb=max(maxb,sum[i-firstlen]-sum[i-firstlen-secondlen]);
            ret=max(ret,max(maxa+sum[i]-sum[i-secondlen],maxb+sum[i]-sum[i-firstlen]));
        }
        return ret;
    }
};

